<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<th:block th:include="include :: jasny-bootstrap-css"/>
<th:block th:include="include :: bootstrap-fileinput-css"/>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-govManage-edit" th:object="${govManage}">
        <input id="id" name="id" th:field="*{id}" type="hidden">
        <input id="govId" name="govId" th:field="*{govId}" class="form-control" type="hidden">

        <div class="form-group">
            <label class="col-sm-3 control-label">政府机构名称：</label>
            <div class="col-sm-8">
                <input id="govName" name="govName" th:field="*{govName}" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">政府机构LOGO：</label>
            <div class="col-sm-5">
                <div class="fileinput fileinput-new" data-provides="fileinput">
                    <div id="coverImgUrl" class="fileinput-preview thumbnail" data-trigger="fileinput"
                         style="width: 200px; height: 120px;"></div>
                    <input id="logoUrl" name="logoUrl" th:field="*{logoUrl}" type="hidden"/>
                    <div>
                        <span class="btn btn-white btn-file"><span class="fileinput-new">选择</span><span
                                class="fileinput-exists">更改</span><input id="img" type="file"></span>
                        <a href="#" class="btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a>
                        <span style="width: 200px; height: 120px; color: red">请选择1M以内图片</span>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-3 control-label">管辖行政区域：</label>
            <div class="col-xs-8">
                <label th:each="region:${regionList}" class="check-box">
                    <input name="regionList" type="checkbox" th:value="${region.regionId}" th:checked="${region.flag}"
                           th:text="${region.regionTitle}">
                </label>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <textarea id="remark" name="remark" rows="5" th:field="*{remark}" class="form-control"></textarea>
            </div>
        </div>
    </form>
</div>
<div th:include="include::footer"></div>
<th:block th:include="include :: jasny-bootstrap-js"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<script type="text/javascript">
    var prefix = ctx + "business/govManage";
    $("#form-govManage-edit").validate({
        rules: {
            xxxx: {
                required: true,
            },
        }
    });

    $(function () {
        $('#img').on('change.bs.fileinput', function (e) {
            var img = e.currentTarget.files[0];
            var formData = new FormData();
            formData.append("file", img);
            $.ajax({
                url: ctx + "business/attachment/upload",
                data: formData,
                type: "post",
                processData: false,
                contentType: false,
                success: function (result) {
                    $("#logoUrl").val(result.url);
                }
            });
        });
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-govManage-edit').serialize());
        }
    }
</script>
</body>
</html>
